package com.liugege.make.singleton;

public class VolatileDemo {
    public static void main(String[] args) {
        InstanceFactory instance = InstanceFactory.getInstance();
        InstanceFactory instance1 = InstanceFactory.getInstance();
        System.out.println(instance == instance1);
    }


}

class InstanceFactory{
    private    static  volatile  InstanceFactory instance ;

    private InstanceFactory() {

    }
    public  static InstanceFactory getInstance(){
        if (instance == null){
            synchronized (InstanceFactory.class){
                if (instance == null){
                    instance = new InstanceFactory();
                }
            }
        }
        return instance;
    }

}